﻿<%inherits "Discuz.Album.Pages.usercpphotoadd"%>
<%template _header%>
<div class="wrap cl pageinfo">
	<div id="nav">
		<%if {usergroupinfo.allowsearch}>0%>
			<%template _quicksearch%>
		<%/if%>
       <a href="{config.forumurl}" class="title">{config.forumtitle}</a>  &raquo; <a href="usercp.aspx">用户中心</a>  &raquo; <a href="usercpspacemanagealbum.aspx">管理相册</a>&raquo; <a href="usercpspacemanagephoto.aspx?albumid={albumid}">管理图片</a>&raquo; <strong>增加图片</strong>
	</div>
</div>
<img id="img_hidden" style="position:absolute;top:-100000px;filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod='image');width:400;height:300"></img>
<div class="wrap uc cl">
	<%template _menu%>
	<div class="uc_main">
	<div class="uc_content">
	<h1 class="u_t">增加图片</h1>
<%if page_err==0%>
	<%if ispost%>
	<%template _usercpmsgbox%>
	<%else%>
	<form action="" method="post" enctype="multipart/form-data">
	<div id="freePhotoSize" style="padding-bottom:10px;"></div>
	<%set (string){tabnum} = "1,2,3,4,5,6"%>
	<%set (char){comma} = ','%>
	<%loop (string) num tabnum.Split(comma)%>
	<table id="tab{num}" cellspacing="0" cellpadding="0" class="tfm" summary="增加图片{num}" <%if {num}!="1"%>style="display:none"<%/if%>>
	<tbody>
		<tr>
			<th>标题</th>
			<td><input name="phototitle{num}" type="text" id="phototitle{num}" size="25" class="txt"/></td>
		</tr>
		<tr>
			<th>选择图片</th>
			<td>
				<input type="file" id="photo{num}" onchange="PhotoView({num})" size="50" name="photo{num}">
			</td>
		</tr>
		<tr>
			<th>描述</th>
			<td><textarea name="description{num}" rows="2" class="txtarea" cols="50"></textarea></td>
		</tr>
		<tr>
			<th></th>
			<td><span id="td{num}"><img src="{spaceurl}space/manage/images/invalid.gif" width="100" height="75" id="view{num}"></span></td>
		</tr>
		<%if {config.enabletag}==1%>
		<tr>
			<th>标签</th>
			<td><input name="phototag{num}" type="text" id="phototag{num}" size="25" class="txt"></td>
		</tr>
		<%/if%>
	</tbody>
	</table>
	<%/loop%>
	<hr class="solidline"/>
	<table cellspacing="0" cellpadding="0" class="tfm" summary="增加图片">
	<tr>
		<th></th>
		<td><button type="submit" name="Submit" class="pn"><span>增加</span></button></td>
	</tr>
	</table>
	</form>
	<%/if%>
<%else%>
	<%template _usercperrmsgbox%>
<%/if%>
	</div>
	</div>
<script type="text/javascript">
	var currentFreePhotoSize = {freephotosize};
	SetMessage(currentFreePhotoSize);
	function PhotoView(layer)
	{
		var file = $("photo" + layer).value;
		if (file != "")
		{
			var patn = /\.jpg$|\.jpeg$|\.gif$|\.png$/i;
			if (!patn.test(file))
			{
				clearFileInput($("photo" + layer));
				alert("相册只允许jpg、jpeg、gif或png格式的图片!");
				return;
			}
			if(document.all) //IE执行
			{
                insertImage(layer);
            }			
		}
		else
		{
			$("view" + layer).src = "{spaceurl}space/manage/images/invalid.gif";

		}
		setTimeout("CalSize()", 500);
		if(layer != 6)
		{
		    $("tab" + (layer + 1)).style.display = 'block'; //显示隐藏的上传框
		}
		document.documentElement.scrollTop = document.documentElement.scrollHeight; //始终将滚动条定位到底部
	}
	
	function insertImage(id) 
    {
    var localimgpreview = '';
    var path = $('photo' + id).value;
    var ext = path.lastIndexOf('.') == -1 ? '' : path.substr(path.lastIndexOf('.') + 1, path.length).toLowerCase();
    var re = new RegExp("(^|\\s|,)" + ext + "($|\\s|,)", "ig");
    var localfile = $('photo' + id).value.substr($('photo' + id).value.replace(/\\/g, '/').lastIndexOf('/') + 1);

    if(path == '') 
    {
        return;
    }

    var err = false;
    $('img_hidden').alt = id;
    try 
    {
        $('img_hidden').filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = 'image';
    } 
    catch (e) 
    {err = true;}
    try 
    {
        $('img_hidden').filters.item("DXImageTransform.Microsoft.AlphaImageLoader").src = $('photo' + id).value;
    } 
    catch (e) 
    {
		alert('无效的图片文件。');
		delAttach(id);

		err = true;		
        
        return;
    }
    var wh = {'w' : $('img_hidden').offsetWidth, 'h' : $('img_hidden').offsetHeight};
    if (wh['w']>100) 
    {
        wh['h']*= 100/wh['w'];
        wh['w']=100;
    }
    if (wh['h']>100) 
    {
        wh['w']*= 100/wh['h'];
        wh['h']=100;
    }
    $('img_hidden').style.width = wh['w'];
    $('img_hidden').style.height = wh['h'];
    try 
    {
        $('img_hidden').filters.item("DXImageTransform.Microsoft.AlphaImageLoader").sizingMethod = 'scale';
    }
    catch (e)
    {
    }
    if (err == true)
    {
        $('img_hidden').src = $('photo' + id).value;
    }
    div = document.createElement('div');
    $('td' + id).removeChild($('td' + id).children(0));
    $('td' + id).appendChild(div);
    div.innerHTML = '<img style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=\'scale\',src=\'' + $('photo' + id).value+'\');width:'+wh['w']+';height:'+wh['h']+'" src=\'images/common/none.gif\' border="0" id="view' + id + '" aid="view'+ id +'" alt="" />';
}
	
	function clearFileInput(file){
		var form = document.createElement('form');
		document.body.appendChild(form);
		var pos = file.nextSibling;
		form.appendChild(file);
		form.reset();
		pos.parentNode.insertBefore(file, pos);
		document.body.removeChild(form);
	}
	function ShowFormatBytesStr(bytes)
	{
		if(bytes > 1073741824)
		{
			return((Math.round((bytes/1073741824)*100)/100).toString()+' GB');
		}
		else if(bytes > 1048576)
		{
			return((Math.round((bytes/1048576)*100)/100).toString()+' MB');
		}
		else if(bytes > 1024)
		{
			return((Math.round((bytes/1024)*100)/100).toString()+' KB');
		}
		else
		{
			return(bytes.toString()+' 字节');
		}
	}

	function CalSize()
	{
		var sumsize = 0;
			for(i = 1 ; i < 7 ; i++)
			{
				if($("photo" + i).value != "")
				{
					var photoSize = $("view" + i).fileSize;
					sumsize += parseInt(photoSize);
				}
			}
			SetMessage(currentFreePhotoSize - sumsize);
	}
	function SetMessage(bytesize)
	{
		if (is_ie && $("freePhotoSize"))
		{
			if(bytesize >= 0)
				$("freePhotoSize").innerHTML = "您还有<font color='#009900'>" + ShowFormatBytesStr(parseInt(bytesize)) + "</font>的上传空间";
			else
				$("freePhotoSize").innerHTML = "<font color='#ff0000'>警告：您已经超过最大上传空间" + -bytesize + "字节</font>";
		}
		
	}

</script>
</div>
<%template _copyright%>
<%template _footer%>